//
//  ExercisesAnswerResultItemCell.m
//  ShowYork
//
//  Created by hxh on 2020/9/11.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "ExercisesAnswerResultItemCell.h"
#import "PaddingLabel.h"
@interface ExercisesAnswerResultItemCell ()
@property (nonatomic,strong)ExercisesQuqestionModel *curentModel;
@property (nonatomic,strong)UIButton *coverBtn;
@property (nonatomic,strong)PaddingLabel *unAnswerLb;
@end

@implementation ExercisesAnswerResultItemCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUI];
    }
    return self;
}

- (void)setUI{
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    self.coverBtn = [[UIButton alloc]init];
    self.coverBtn.layer.cornerRadius = 19;
    self.coverBtn.layer.masksToBounds = YES;
    [self.coverBtn addTarget:self action:@selector(coverMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.coverBtn];
    [self.coverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(38, 38)).priorityLow();
        make.top.left.bottom.right.mas_equalTo(self.contentView);
        
    }];
    self.unAnswerLb = [[PaddingLabel alloc]init];
    self.unAnswerLb.text = @"未答";
    self.unAnswerLb.textColor = [UIColor whiteColor];
    self.unAnswerLb.font = font(10);
    self.unAnswerLb.backgroundColor = RGBA(255, 100, 99, 1);
    self.unAnswerLb.layer.borderWidth = 1;
    self.unAnswerLb.layer.borderColor = [UIColor whiteColor].CGColor;
    self.unAnswerLb.layer.cornerRadius = 3;
    self.unAnswerLb.layer.masksToBounds = YES;
    self.unAnswerLb.hidden = YES;
    self.unAnswerLb.edgeInsets = UIEdgeInsetsMake(2, 5, 2, 5);
    [self.contentView addSubview:self.unAnswerLb];
    
    [self.unAnswerLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView).offset(19);
        make.top.mas_equalTo(self.contentView).offset(-8);
    }];
}

- (void)setResultItem:(ExercisesQuqestionModel *)resModel atIndex:(NSInteger)index{
   
    self.curentModel = resModel;
    

//    // 判断是否是后台补充
    if (resModel.answerItem == nil) {
        if (resModel.questionType.intValue == 5) {
            self.unAnswerLb.hidden = YES;
            self.coverBtn.backgroundColor = RGBA(229, 229, 229, 1);
        }else{
            self.unAnswerLb.hidden = NO;
            self.coverBtn.backgroundColor = RGBA(255, 100, 99, 1);
        }
    }else{
        if (resModel.answerItem.doRight) {
            // 判断是否是不计分
            if (resModel.answerItem.content.length == 0) {
                // 灰色 不可积分
                self.coverBtn.backgroundColor = RGBA(229, 229, 229, 1);
            }else{
                // 绿色 已做答
                self.coverBtn.backgroundColor = RGBA(109, 221, 127, 1);
            }
        }else{
            // 判断是否答题
            if (resModel.answerItem.content.length == 0) {
                self.unAnswerLb.hidden = NO;
            }else{
                self.unAnswerLb.hidden = YES;
            }
            // 红色判断是否作答
            self.coverBtn.backgroundColor = RGBA(255, 100, 99, 1);
        }
    }
    [self.coverBtn setTitle:[NSString stringWithFormat:@"%lu",index + 1] forState:UIControlStateNormal];
    // 做错
}
- (void)coverMethod{
    if (self.delegate && [self.delegate respondsToSelector:@selector(didSelecteAtIResultItem:)]) {
        [self.delegate didSelecteAtIResultItem:self.curentModel];
    }
}
@end
